package com.tutorialspoint;

// import org.springframework.beans.factory.xml.XmlBeanFactory;

// import java.io.File;

import org.springframework.context.ApplicationContext;
// import org.springframework.context.support.AbstractApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
// import org.springframework.context.support.FileSystemXmlApplicationContext;
// import org.springframework.core.io.ClassPathResource;

public class IoC {
	public static void main(String[] args) {
		/*
		// Hello world instance
		ApplicationContext context = 
				new ClassPathXmlApplicationContext("Beans.xml");
		HelloWorld obj = (HelloWorld) context.getBean("helloworld");
		obj.getMessage();*/
		
		/*
		BeanFactory container
		XmlBeanFactory factory = 
				new XmlBeanFactory(new ClassPathResource("Beans.xml"));
		HelloWorld obj = (HelloWorld) factory.getBean("helloworld");
		obj.getMessage();*/
		
		/*
		// ApplicationContext container
		ApplicationContext context = new FileSystemXmlApplicationContext(
				"src/Beans.xml");
		HelloWorld obj = (HelloWorld) context.getBean("helloworld");
		obj.getMessage();*/
		
		/*
		// Bean action scope
		ApplicationContext context_singleton = 
				new ClassPathXmlApplicationContext("Beans.xml");
		HelloWorld obj_singleA = (HelloWorld) context_singleton.getBean("helloworld");
		obj_singleA.setMessage("I'm object A");
		obj_singleA.getMessage();
		HelloWorld obj_singleB = (HelloWorld) context_singleton.getBean("helloworld");
		obj_singleB.getMessage();
		((ClassPathXmlApplicationContext)context_singleton).close();
		ApplicationContext context_proto = 
				new ClassPathXmlApplicationContext("Beans_scope_proto.xml");
		HelloWorld obj_protoA = (HelloWorld) context_proto.getBean("helloworld");
		obj_protoA.setMessage("I'm object A");
		obj_protoA.getMessage();
		HelloWorld obj_protoB = (HelloWorld) context_proto.getBean("helloworld");
		obj_protoB.getMessage();
		((ClassPathXmlApplicationContext)context_proto).close();*/
		/*
		// life cycle
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("Beans.xml");
		HelloWorld obj = (HelloWorld) context.getBean("helloworld");
		obj.getMessage();
		context.registerShutdownHook();*/
		/*
		// BeanPostProcessor
		AbstractApplicationContext context = new ClassPathXmlApplicationContext("Beans_postProcessor.xml");
		HelloWorld obj = (HelloWorld) context.getBean("helloworld");
		obj.getMessage();
		context.registerShutdownHook();
		*/
		//inherit
		@SuppressWarnings("resource")
		ApplicationContext context = new 
				ClassPathXmlApplicationContext("Beans_inherit.xml");
		HelloWorld objA = (HelloWorld) context.getBean("helloWorld");
		objA.getMessage1();
		objA.getMessage2();
		HelloChina objB = (HelloChina) context.getBean("helloChina");
		objB.getMessage1();
		objB.getMessage2();
		objB.getMessage3();
		
	}

}
